package com.shiliuzi.www.controller;

import com.shiliuzi.www.pojo.dto.user.*;
import com.shiliuzi.www.service.LoginService;
import com.shiliuzi.www.service.UserService;
import com.shiliuzi.www.common.Result;
import com.shiliuzi.www.util.powerUtil.Power;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//@Controller
@RestController
@RequestMapping("/User")
@CrossOrigin
public class UserController {

    @Resource
    private LoginService loginService;

    @Resource
    private UserService userService;

    @PostMapping("/login/sendEmail")
    public Result sendEmail(@Validated @RequestBody UserLoginSendDto userLoginSendDto) {
        return loginService.loginSendEmail(userLoginSendDto);
    }

    @PostMapping("/login/loginCheck")
    public Result loginCheck(@Validated @RequestBody UserLoginCheckDto userLoginCheckDto) {
        return loginService.loginCheck(userLoginCheckDto);
    }

    @GetMapping("/login/out/limit")
    public Result loginOut() {
        return loginService.loginOutOfTable();
    }

    /**
     * 管理员获取成员信息
     * @return
     * @author liuyixin
     */
    //TODO 参数名字，支持模糊查询，分页展示
    @PostMapping("/member/getMember")
    public Result getMemberInfo(@RequestParam UserSelectDto userSelectDto) {
        return userService.managerSelect(userSelectDto);
    }

    /**
     * 超级管理员提供角色
     * @return
     * @author guojunji
     */
    @Power(powId = 1)
    @PostMapping("/manager/setRole")
    public Result setMemberRole(@Validated @RequestBody UserSetRoleDto userSetRoleDto) {
        return userService.setMemberRole(userSetRoleDto);
    }

    /**
     * 普通成员可以查看上下级
     * @param type 0表示只查上级，1表示只查下级，2表示全查
     * @return
     */
    @Power(powId = 13)
    @GetMapping("/member/getUpLowMember")
    public Result getUpLowMember(@RequestParam("type") Integer type) {
        return userService.getUpLowMember(type);
    }

    /**
     * 管理员设置成员上下级
     * @return
     * @author guojunji
     */
    @Power(powId = 1)
    @PutMapping("/manager/setUpMember")
    public Result setUpMember(@Validated @RequestBody UserUpMemberDto userUpMemberDto) {
        return userService.setUpMember(userUpMemberDto);
    }
}
